import { message } from "ant-design-vue";
import { Ref } from "vue";

export default function InitHook(state: { pastId: Ref<string>; maxCount: Ref<number>; fileList: Ref<Array<Base.GeneraDataType>> }) {
  const { pastId, maxCount, fileList } = state;
  const initPastImg = () => {
    const pastDom = document.getElementById(pastId.value);
    const pastTipDom = document.querySelector(".past-wrapper > .past-tip");
    if (pastTipDom) {
      pastTipDom.addEventListener("click", () => {
        pastDom?.focus();
      });
      pastDom?.addEventListener("click", (e: any) => {
        if (maxCount.value > fileList.value.length) return message.error(`最多上传${maxCount.value}张图片!`);
        const items = (e.clipboardData || window.Clipboard).files;
        if (items && items.length) {
          console.log("粘贴的图片", items);
        }
      });
    }
  };
  return {
    initPastImg
  };
}
